package com.jinghong.epidemiccontrolproject.service.impi;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jinghong.epidemiccontrolproject.mapper.UserMapper;
import com.jinghong.epidemiccontrolproject.pojo.User;
import com.jinghong.epidemiccontrolproject.pojo.PageBean;
import com.jinghong.epidemiccontrolproject.service.UserService;
import com.jinghong.epidemiccontrolproject.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:UserServiceimpi
 * Package:com.jingjian.gamesetupapp.service.impi
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2023/12/18 22:27
 * Version:1.0
 */
@Service
public class UserServiceimpi implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String username) {
        User u = userMapper.findByUserName(username);
        return u;
    }
    @Override
    public void register(String username, String password) {
        //加密
        String md5String = Md5Util.getMD5String(password);
        //添加
        userMapper.add(username,md5String);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String username) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<User> userList = userMapper.list(username);
        Page<User> p = (Page<User>) userList;

        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        userMapper.delete(ids);
    }



    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public User getById(Integer id) {
        return userMapper.getById(id);
    }

    @Override
    public User login(User user) {
        return userMapper.getByUsernameAndPassword(user);
    }
}
